////////////////////////////////////////////////////////////////////////////////////////////
//CodecManager.h
//
//Copyright 2010 Eric Callahan. All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY ERIC CALLAHAN ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ERIC CALLAHAN OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Eric Callahan.
////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

// Windows Header Files:
#include <windows.h>
#include <strsafe.h>
#include <dshow.h>
#include <string>

// DShow related headers
#include "wmcodecdsp.h"
#include "dshowutil.h"
#include "Bdaiface.h"
#include "CustomGUIDS.h"

enum FilterType {CAP_FILTER, AUDIO_CODEC, VIDEO_CODEC};

// The enumerations and constants below pertain to supported directshow filters
// by the application.  Any additional supported filters must be added here, and
// the count must be incremented
enum VidFilter {ARCSOFT_VIDEO, MS_VIDEO};
enum AudFilter {ARCSOFT_AUDIO, MS_AUDIO, FFDSHOW_AUDIO};
enum CapFilter {HDPVR_CROSSBAR, HDPVR_CAPTURE, HDPVR_ENCODER};

const int SUPPORTED_VID_FILTER_COUNT = 3;
const int SUPPORTED_AUD_FILTER_COUNT = 2;
const int SUPPORTED_CAP_FILTER_COUNT = 3;

using namespace std;

// Structure containing information pertinent to directshow filters.
// Makes it easy to identify and relay info across the app.
struct FilterIdent
{
	string friendlyName;

	FilterType curFilType;

	// Gives quick identification of the filter
	union {
		VidFilter curVidDec;
		AudFilter curAudDec;
		CapFilter curCapFilter;
	};

	// This union is for storing information needed to add a filter to the filter
	// graph.  Most codec's can be added by CLSID, but capture devices share a common CLSID,
	// so they are added by the filter's Moniker.
	union {
		GUID filterCLSID;
		IMoniker* pFilterMoniker;
	};
};

class CodecManager
{

public:
	CodecManager(void);
	~CodecManager(void);

	// Allow caller to get lists of supported codecs currently on the user's system
	HRESULT GetVidDecID (FilterIdent** vidDec, const VidFilter& index) const;
	HRESULT GetAudDecID(FilterIdent** audDec, const AudFilter& index) const;
	HRESULT GetCapID (FilterIdent** capFilter, const CapFilter& index) const;

	// NOTE: at this point, we only support one capture device (HDPVR),
	//		 these are here for future extensibility 
	//BSTR* GetCapDevList();

private:
	HRESULT EnumerateSupportedCodecs();
	HRESULT EnumerateCaptureDevice();
	BOOL IsFilterRegistered(LPCWSTR keyLoc);

	FilterIdent** m_vidDecs;	  // array of supported video decoders
	FilterIdent** m_audDecs;	  // array of supported audio decoders
	FilterIdent** m_capFilters;   // array of supported capture device filters
};

